package com.example.bishe.web.b.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.bishe.entity.Approval;
import com.example.bishe.service.ApprovalService;
import com.example.bishe.util.RestResult;
import com.example.bishe.web.b.vo.getApprovalPageVO;
import com.example.bishe.web.b.vo.getRoomPageVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LDH
 * @since 2022/11/30
 */
@RestController
@RequestMapping("/b/approval")
public class ApprovalController {

    @Autowired
    private ApprovalService approvalService;

    @ApiOperation("审批数据分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "审批流水号", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "审批申请人id", paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "审批申请人昵称", paramType = "query"),
            @ApiImplicitParam(name = "result", value = "审批结果", paramType = "query")
    })
    @GetMapping("/page")
    public RestResult<IPage<getApprovalPageVO>> page(
            @RequestParam(required = false,defaultValue = "1")  int pageNum,
            @RequestParam(required = false,defaultValue = "10") int pageSize,
            @RequestParam(required = false) Long id,
            @RequestParam(required = false) Long userId,
            @RequestParam(required = false) String userName,
            @RequestParam(required = false) Integer result,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime
    ){
        IPage<getApprovalPageVO> page = approvalService.getApprovalPage(pageNum,pageSize,id,userId,userName,result,startTime,endTime);
        return RestResult.get_success(page);
    }

    @ApiOperation("管理员审批待审批数据")
    @PutMapping("/update")
    public RestResult<Void> update(@RequestBody Approval approval){
        approvalService.update(approval);
        return RestResult.set_success("审批成功");
    }

    @ApiOperation("管理员删除审批数据")
    @DeleteMapping("/delOne")
    public RestResult<Void> delOne(@RequestBody Approval approval){
        approvalService.delOne(approval);
        return RestResult.set_success("删除成功！");
    }

    @ApiOperation("管理员批量删除审批数据")
    @DeleteMapping("/delBatch")
    public RestResult<Void> delBatch(@RequestBody List<Approval> approvals){
        approvalService.delBatch(approvals);
        return RestResult.set_success("批量删除成功！");
    }

}
